<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<style>
			.hb1{}
			.hb2{}
		</style>
	</head>

	<body>
		<script src="js/mui.js"></script>
		<script type="text/javascript">
			var group = 1;

			mui.init();
			mui.plusReady(function() {
				bjid = plus.storage.getItem("scanbj");
				te = JSON.parse(plus.storage.getItem("classList"));
				window.studentSeat = JSON.parse(plus.storage.getItem("studentSeat"));
				window.Rid = 'R' + bjid.toString();
				if (typeof(window.studentSeat[Rid]) == "undefined") {
					window.studentSeat[Rid] = {};
					window.studentSeat[Rid]['1'] = {};
					
					save_();
					window.group = 1;
					addGroup(window.group);
				} else {
					//alert(plus.storage.getItem("studentSeat"));

					//alert(Object.keys(studentSeat[Rid]).length);
					var maxid=0;
					for (var k in studentSeat[Rid]) {
						if(parseInt(k)>maxid){
							maxid=parseInt(k);
						}
						//addGroup(parseInt(k));
					}
					for (var i=1; i<=maxid; i++){
						addGroup(parseInt(i));
					}
				}

				mui.each(te, function(k, v) {
					//alert(JSON.stringify(v));
					if (v.id == bjid) {
						mui(".mui-title")[0].innerHTML = '初' + v.grade + ' ' + v.alias + "班";
					}
				});
				mui('body').on("tap", "button.hb1", function() {
					alert("clear" + this.getAttribute("data-v"));
					alert(JSON.stringify(studentSeat[Rid]));
				});
				mui('body').on("tap", "button.hb2", function() {
					//alert(this.getAttribute("data-v"));
					plus.storage.setItem("studentG", this.getAttribute("data-v"));

					document.location.href = "scan.html";
				});
				//addGroup(1);
			});

			function addGroup(id) {
				if (plus.storage.getItem("downLoadStudentInfo") == null) {
					alert('请下载学生信息');
					scan.close();
					window.location.href = 'index.html';
				} else {
					json = JSON.parse(plus.storage.getItem("downLoadStudentInfo"));
					window.sinfo = {};
					mui.each(json, function(k, v) {
						sinfo['s' + v.ID] = v;
					});
				}
				//alert(window.studentSeat[window.Rid][id]);
				gr = document.getElementById("gro");
				var hd = document.createElement("div");
				var hh = document.createElement("div");
				var hb = document.createElement("div");
				var hc = document.createElement("button");
				var hs = document.createElement("button");
				hd.className = 'mui-card mui-row';
				hh.className = "mui-card-header";
				hb.className = "mui-card mui-row";
				//hb.setAttribute("style", "padding: 5px;");
				hb.innerHTML = "";
				num_ = 1;
				if(typeof(studentSeat['R' + bjid][id])=="undefined"){
					studentSeat['R' + bjid][id]={};
				};
				for (var k in studentSeat['R' + bjid][id]) {
					//alert(window.sinfo);
					sin = window.sinfo['s' + studentSeat['R' + bjid][id][k]['id']];
					//alert(studentSeat['R' + bjid][id][k]['id']); 
					hb.innerHTML = hb.innerHTML + "<div class='mui-card-content mui-col-xs-1'> &nbsp;" + num_.toString() +
						"</div><div class='mui-card-content mui-col-xs-5'>初" + sin.grade + sin.class + "班" + sin
						.name +
						"</div><div class='mui-card-content mui-col-xs-6'>" + sin.ID + "</div>";
					num_ += 1;
				}

				//<button class=\"mui-btn-primary hb1\" data-v=\"" + id.toString() +"\">清除</button>
				hh.innerHTML = "第" + id + "小组" + "<button class=\"mui-btn-primary hb2\" data-v=\"" + id.toString() +
					"\">扫描</button>";;
				hd.appendChild(hh);
				hd.appendChild(hb);
				gr.appendChild(hd);
				window.group = id + 1;


			}

			function back_() {
				save_();
				history.back(-1);
			}

			function save_() {
				//alert(JSON.stringify(studentSeat));
				plus.storage.setItem("studentSeat", JSON.stringify(studentSeat));
				//document.location.href = "index.html";
				//history.back(-1);
			}
		</script>
		<header id="header" class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">班级列表</h1>
		</header>
		<div class="mui-content">

			<div id="gro">
				<!-- <div class="mui-card mui-row" id="g1"> -->
				<!--页眉，放置标题-->
				<!-- <div class="mui-card-header">第一组 -->
				<!-- <button class="mui-btn-primary hb1" data-v="1">清除</button> -->
				<!-- <button class="mui-btn-primary hb2" data-v="1">扫描</button> -->
				<!-- </div> -->
				<!-- <div class="mui-card-content mui-col-xs-6" style="padding: 5px;"></div> -->
				<!-- <div class="mui-card-content mui-col-xs-6" style="padding: 5px;"></div> -->
			</div>
		</div>
		<div class="mui-content-padded">
			<button class="mui-btn-primary mui-btn-block" onclick="addGroup(window.group);">添加</button>
			<button class="mui-btn-primary mui-btn-block" onclick="back_();">返回</button>
		</div>
		</div>
	</body>

</html>
